const Router = require('@koa/router')
const query = require('./db')

const router = new Router();

router.post('/api/add-types', async ctx => {
  const { name } = ctx.request.body;
  let sql = `insert into types (name) values ('${name}')`
  const res = await query(sql)
  if (res.affectedRows) {
    ctx.body = {
      code: 200,
      msg: '添加成功'
    }
  } else {
    ctx.body = {
      code: 400,
      msg: '添加失败'
    }
  }
})

module.exports = router;